package com.zhangjie.servicemap.remote;

import com.zhangjie.internalcommon.constant.AmapConfigConstants;
import com.zhangjie.internalcommon.dto.ResponseResult;
import com.zhangjie.internalcommon.response.DirectionResponse;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: zj
 * @Date: 2024/2/6 - 02 - 06 - 15:47
 * @Description: com.zhangjie.servicemap.remote
 * @version: 1.0
 */
@Service
@Slf4j
public class MapDicDistrictClient {

    @Value("${amap.key}")
    private String amapKey;

    @Autowired
    private RestTemplate restTemplate;

    public String dicDistrict(String keywords){

        // 拼装请求url
        StringBuilder url = new StringBuilder();
        url.append(AmapConfigConstants.DISTRICT_URL);
        url.append("?");
        url.append("keywords=" + keywords);
        url.append("&");
        url.append("subdistrict=3");
        url.append("&");
        url.append("key=" + amapKey);

        // 调用高德接口
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);


        return forEntity.getBody();
    }
}
